#pragma once
#ifndef MQTTCLIENT_H
#define MQTTCLIENT_H

#include <thread>
#include <mutex>
#include <string>
#include "mosquitto.h"

class MQTTClient {
private:
    mosquitto* mosq;
    mosquitto* mosq1;
    bool should_continue = false;
    std::thread loop_thread;
    std::mutex mtx;
    std::string last_message;

public:
    MQTTClient(const std::string& host, int port, const std::string& user, const std::string& password, const std::string& cafile);
    ~MQTTClient();
    void start();
    void stop();
    void subscribe(const std::string& topic);
    std::string getLastMessage();
    void publish(const std::string& topic, const std::string& message);

private:
    static void on_message(struct mosquitto* mosq, void* userdata, const struct mosquitto_message* message);
    void loop();
};

#endif // MQTTCLIENT_H

